﻿// Study0404.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第四章 类和对象 类组合构造函数
#include <iostream>
#include <cmath>
using  namespace std;
class Point
{
public:
	Point(int xx = 0, int yy = 0) :x(xx), y(yy) {}
	Point(const Point& p);
	int getX() const {
		return x;
	}
	int getY() const {
		return y;
	}
private:
	int x, y;
};


Point::Point(const Point& p)
{
	x = p.getX();
	y = p.getY();
	cout << "("<<p.getX()<<","<<p.getY()<<")"<<"已执行点的复制构造函数"<<endl;
}


class Line
{
public:
	Line(Point p1, Point p2);
	Line(const Line& l);
	double getLen() const {
		return len;
	}
private:
	Point p_start, p_end;
	double len;
};

inline Line::Line(Point p1, Point p2):p_start(p1),p_end(p2)
{
	cout << "完成直线的构造函数"<<endl;
	int x = p1.getX() - p2.getX();
	int y = p1.getY() - p2.getY();
	len = sqrt(x * x + y * y);
}

Line::Line(const Line& l)
{
	p_start = l.p_start;
	p_end = l.p_end;
	len = l.len;
	cout << "完成直线的复制构造函数" << endl;
}


int main()
{
	Point myP1(1, 1), myP2(4, 5);
	Line line(myP1, myP2);
	Line line2(line);
	cout << "The length of the line is: ";
	cout << line.getLen() << endl;
	cout << "The length of the line2 is: ";
	cout << line2.getLen() << endl;
	return 0;

}


